package com.dreamweaver.mvvmtest.model;

import android.os.Handler;
import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.dreamweaver.mvvmtest.bean.LoginInfo;
import com.dreamweaver.mvvmtest.bean.LoginResponse;
import com.dreamweaver.mvvmtest.constant.LogTag;

public class LoginModel extends ViewModel {
    private final MutableLiveData<LoginResponse> loginResponseLiveData
            = new MutableLiveData<>();

    public MutableLiveData<LoginResponse> getLoginResponseLiveData() {
        return loginResponseLiveData;
    }

    public void Login(final LoginInfo loginInfo) {
        if (loginInfo == null) {
            Log.e(LogTag.COMMON, "loginInfo 不能为空");
            return;
        }
        Log.i(LogTag.COMMON, "正在登陆，用户名为：" + loginInfo.toString() +
                ";密码为：" + loginInfo.getPassword());
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                loginResponseLiveData.postValue(
                        new LoginResponse(loginInfo.getUserName(), "qwertyuiop", 12));
            }
        }, 1000);
    }
}
